<?php
class login extends controller{
	public function __construct($url){
		parent::__construct($url);
	}
	
	public function check(){
		if(isset($_SESSION["user"]) && !empty($_SESSION["user"])){
			$this->redirect("start");
		}
	}

	public function run(){
		$this->login();
	}

	private function login(){
		if(isset($_POST["login"])){
			if(!empty($_POST["username"]) && !empty($_POST["password"])){
				$sql = "SELECT * FROM user WHERE id > 0 AND username = '".$_POST["username"]."' AND password = '".md5($_POST["password"])."'";
				$tmp = $this->database->fetchRow($sql);
				$_SESSION["user"] = $tmp[0];
				$this->redirect("start");
			}
			else{
				$this->message = "Üresen hagyott mező!";
			}
		}
	}
}
?>
